package com.example.demospring.controller.counselor;


import com.example.demospring.dto.counselor.AdditionalTimeAppointmentDTO;
import com.example.demospring.service.counselor.AdditionalTimeAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/additional-appointments")
public class AdditionalTimeAppointmentController {

    @Autowired
    private AdditionalTimeAppointmentService service;

    @GetMapping
    public Page<AdditionalTimeAppointmentDTO> list(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String date,
            @RequestParam(required = false) String timeSlot,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        LocalDate d = (date != null && !date.isEmpty()) ? LocalDate.parse(date) : null;
        return service.findPage(name, d, timeSlot, page, size);
    }

    @GetMapping("/{id}")
    public AdditionalTimeAppointmentDTO get(@PathVariable Integer id) {
        return service.getById(id);
    }

    @PostMapping
    public AdditionalTimeAppointmentDTO save(@RequestBody AdditionalTimeAppointmentDTO dto) {
        return service.saveOrUpdate(dto);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        service.delete(id);
    }
}